package com.usain.controller;

import com.usain.pojo.Teacher;
import com.usain.service.TeacerService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;
import javax.websocket.server.PathParam;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/demo")
public class TeacherController {
    @Autowired
    private TeacerService teacerService;

    @GetMapping("/find")
    public List<Teacher> findTeacher(){
        List<Teacher> teachers=teacerService.findTeacher();
        System.out.println(teachers.toString());
        return teachers;
    }

    @PostMapping("/toAdd")
    public void AddTeacher(@RequestBody Teacher teacher){
        teacerService.AddTeacher(teacher);
    }

    @GetMapping("/findById/{id}")
    public Teacher findById(@PathVariable("id") Integer id){
        return teacerService.findById(id);
    }
    @PostMapping("/Update")
    public void Update(@RequestBody Teacher teacher){
        teacerService.Update(teacher);
    }

    @Delete("/delete/{id}")
    public void Delete(@PathVariable("id") Integer id){
        teacerService.Delete(id);
    }


    @GetMapping("/three")
    public  String  three(){
        System.out.println("放行");
        return "ok";
    }

}
